package ls.vuecp.gui.view;

import java.awt.Component;
import java.awt.geom.Point2D;
import java.io.File;

import tufts.Util;
import tufts.vue.DEBUG;
import tufts.vue.VUE;

import ls.vuecp.gui.component.LWComponent;
import ls.vuecp.gui.component.LWMap;
import ls.vuecp.gui.component.LWNode;
import ls.vuecp.gui.component.RichTextBox;
import ls.vuecp.gui.component.TextBox;

public class MapViewer extends TimedASComponent

{
	private static final org.apache.log4j.Logger Log = org.apache.log4j.Logger.getLogger(MapViewer.class);
	
	public MapViewer(String instanceName)
	{
		this.instanceName = instanceName;
//      this.activeTool = VUE.getActiveSubTool();
//      if (activeTool == null) {
//          // default tool is first in list
//          activeTool = VueTool.getTools().get(0);
//      }
//      this.mapDropTarget = new MapDropTarget(this); // new CanvasDropHandler
//      this.setDropTarget(new java.awt.dnd.DropTarget(this,
//                                                     MapDropTarget.ACCEPTABLE_DROP_TYPES,
//                                                     mapDropTarget));
      this.inputHandler = this;
      this.viewer = this;
      
      setName(instanceName);
      
      //setFocusable(false);
      setOpaque(true);
      setLayout(null);
	}

	private final String instanceName;
    protected LWComponent mFocal;
    protected LWMap mMap;
    protected LWComponent mLastFocal;
    protected TextBox activeTextEdit;
    protected RichTextBox activeRichTextEdit;
    
    private final MapViewer inputHandler; // == this
    private final MapViewer viewer;
    
    private LWNode testNode;
    //-------------------------------------------------------
    // Pan & Zoom Support
    //-------------------------------------------------------
    // package-private for MapViewport class
    double mZoomFactor = 1.0;
    double mZoomInverse = 1/mZoomFactor;
    final Point2D.Float mOffset = new Point2D.Float();
    
    //-------------------------------------------------------
    // Scroll-pane support
    //-------------------------------------------------------
    private boolean inScrollPane = false;
    private MapViewport mViewport;
    private boolean isFirstReshape = true;
    private boolean didReshapeZoomFit = false;
    private Component mFocusIndicator = new java.awt.Canvas(); // make sure is never null
    private boolean mFitToFocalRequested = false;
    
    public void addMap(LWMap map)
	{
		if (map != null) {
            //if (map.getFillColor() != null) setBackground(map.getFillColor());
			mMap = map;
            loadFocal(map);
//        
//            //-------------------------------------------------------
//            // If this map was just restored, there might
//            // have been an existing userZoom or userOrigin
//            // set -- we honor that last user configuration here.
//            //-------------------------------------------------------
//            if (!AutoZoomToMapOnLoad && map.getUserZoom() != 1.0)
//                setZoomFactor(getMap().getUserZoom(), false, null, false);
            
            testNode = new LWNode("Test Node");
            map.addChild(testNode);
        }
//        draggedSelectionGroup.setSelected(true);
	}
    
    public LWMap getMap() {// TODO: make PRIVATE and then clean up to use focals instead as needed (e.g., for drops)
        return mMap == null ? (mFocal == null ? null : mFocal.getMap()) : mMap;
    }
    
    public void loadFocal(LWComponent focal) {
        loadFocal(focal, true, false);
    }
	public void loadFocal (final LWComponent focal,	final boolean fitToFocal,
			final boolean animate)
	{
		
	}
	
	
}
